package test_achieve.web;

import constant.WebCityId;
import constant.Constant;
import constant.VehicleId;
import cucumber.api.java.en.Given;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import util.tools.CommonTools;

/**
 * Created by chenkuo on 2017/8/3.
 */
public class Merchant {


    @Given("^w指定配送方式:(.+)$")
    public void w指定配送方式交通工具(String vehicle) throws Throwable {
        String vehicle1a = "//*[@id=\"container_wrapper\"]/div[2]/div[1]/div/div[3]/div[4]/div[3]/div[2]/div/div[" + VehicleId.getVehicleCodeByName(vehicle) + "]";
        CommonTools.scrollToElement(Constant.driverWeb,By.xpath(vehicle1a));
        WebElement vehicle1 = Constant.driverWeb.findElement(By.xpath(vehicle1a));//交通方式
        vehicle1.click();
        if (vehicle.equals("摩托车")){
            Constant.orderMoto=2;
            System.out.print(Constant.orderMoto);
        }

    }

    @Given("^w验证交通工具费用：(.+)$")
    public void w验证交通工具费用交通费(String ABC) throws Throwable {
//        WebElement identification = Constant.driverWeb.findElement(By.id("price-detail-btn"));//定位价格标识：小问号
        WebElement identification = Constant.driverWeb.findElement(By.xpath(" //*[@id=\"container_wrapper\"]/div[2]/div[1]/div/div[3]/div[4]/div[4]/div[2]/div[3]"));//定位价格标识：小问号

        String details = identification.getText();
//        System.out.println(details);

    }

    @Given("^w输入代收货款金额：(.+)$")
    public void w输入代收货款金额代收货款(String collect) throws Throwable {
        WebElement goodspay = Constant.driverWeb.findElement(By.xpath("//*[@id=\"goodspay\"]"));//代收货款输入框
        goodspay.sendKeys(collect);
        Thread.sleep(2000);

    }

    @Given("^w进入我的货款中$")
    public void w进入我的货款中() throws Throwable {
        OrderMain orderMain = new OrderMain();
        orderMain.w进入我的闪送中();
        Constant.driverWeb.findElement(By.linkText("我的货款")).click();



    }

    @Given("^w获取我的货款余额：(.+)$")
    public void w获取我的货款余额(String city) throws Throwable {
        w进入我的货款中();
        WebElement city3 = Constant.driverWeb.findElement(By.xpath("//*[@id=\"cityList\"]/li["+ WebCityId.getCityCodeByName(city)+"]"));//因为有bug导致需要选择城市
        city3.click();
        Constant.goodsMoney=Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[1]/span[2]/span[1]")).getText();
    }

    @Given("^w显示代收金额：(.+)$")
    public void w显示代收金额代收货款() throws Throwable {
        Constant.driverWeb.findElement(By.xpath("(.+)"));
    }
}
